Skip to content

AbstractButtonMixin

Sub classes

Name Children Inherits
AbstractButton
prettyqt.widgets.abstractbutton
    PushButtonMixin
    prettyqt.widgets.pushbutton
    ToolButton
    prettyqt.widgets.toolbutton
    Quick-access button to commands or options, usually used inside a QToolBar.
    RadioButton
    prettyqt.widgets.radiobutton
    Radio button with a text label.
      CheckBox
      prettyqt.widgets.checkbox
      Checkbox with a text label.

      Base classes

      Name Children Inherits
      WidgetMixin
      prettyqt.widgets.widget
      object
      builtins
      The base class of the class hierarchy.
      • type
      • async_generator
      • bytearray_iterator
      • bytearray
      • bytes_iterator
      • bytes
      • builtin_function_or_method
      • callable_iterator
      • PyCapsule
      • cell
      • classmethod_descriptor
      • ...

        ⋔ Inheritance diagram

        graph TD
          2670709832["widgets.AbstractButtonMixin"]
          829357528["widgets.WidgetMixin"]
          3227531497["core.ObjectMixin"]
          2751680898["builtins.object"]
          625385617["gui.PaintDeviceMixin"]
          829357528 --> 2670709832
          3227531497 --> 829357528
          2751680898 --> 3227531497
          625385617 --> 829357528
          2751680898 --> 625385617
          2751680898 --> 829357528
          2751680898 --> 2670709832

        🛈 DocStrings

        Bases: WidgetMixin, _AbstractButtonBase

        Abstract button widget base class, providing functionality common to buttons.

        Source code in prettyqt/widgets/abstractbutton.py
        class AbstractButtonMixin(widgets.WidgetMixin, _AbstractButtonBase):
            """Abstract button widget base class, providing functionality common to buttons."""
        
            def __bool__(self):
                return self.isChecked()
        
            def set_icon(self, icon: datatypes.IconType):
                """Set the icon for the button.
        
                Args:
                    icon: icon to use
                """
                icon = iconprovider.get_icon(icon)
                self.setIcon(icon)
        
            def get_icon(self) -> gui.Icon | None:
                icon = self.icon()
                return None if icon.isNull() else gui.Icon(icon)
        
            def set_style_icon(
                self,
                icon: widgets.style.StandardPixmapStr | widgets.QStyle.StandardPixmap,
                size: datatypes.SizeType = 15,
            ):
                """Set theme icon for the button.
        
                Args:
                    icon: icon to use
                    size: icon size
                """
                qicon = self.style().standardIcon(
                    widgets.style.STANDARD_PIXMAP.get_enum_value(icon), None, self
                )
                self.set_icon(qicon)
                self.setIconSize(datatypes.to_size(size))
        
            def set_shortcut(self, shortcut: datatypes.KeySequenceType):
                self.setShortcut(datatypes.to_keysequence(shortcut))
        
            def get_shortcut(self) -> gui.KeySequence:
                return gui.KeySequence(
                    self.shortcut().toString(), gui.KeySequence.SequenceFormat.PortableText
                )
        
            def setText(self, text: str):
                if not self.objectName() and widgets.application.is_debug():
                    self.setObjectName(text)
                super().setText(text)
        
            set_text = setText
        
            def set_icon_size(self, size: datatypes.SizeType):
                """Set size of the icon."""
                self.setIconSize(datatypes.to_size(size))
        
            def get_icon_size(self) -> core.Size:
                return core.Size(self.iconSize())
        
            def get_value(self) -> bool:
                return self.isChecked()
        
            def set_value(self, value: bool):
                self.setChecked(value)
        

        set_icon(icon: datatypes.IconType)

        Set the icon for the button.

        Parameters:

        Name Type Description Default
        icon IconType

        icon to use

        required
        Source code in prettyqt/widgets/abstractbutton.py
        def set_icon(self, icon: datatypes.IconType):
            """Set the icon for the button.
        
            Args:
                icon: icon to use
            """
            icon = iconprovider.get_icon(icon)
            self.setIcon(icon)
        

        set_icon_size(size: datatypes.SizeType)

        Set size of the icon.

        Source code in prettyqt/widgets/abstractbutton.py
        def set_icon_size(self, size: datatypes.SizeType):
            """Set size of the icon."""
            self.setIconSize(datatypes.to_size(size))
        

        set_style_icon(icon: widgets.style.StandardPixmapStr | widgets.QStyle.StandardPixmap, size: datatypes.SizeType = 15)

        Set theme icon for the button.

        Parameters:

        Name Type Description Default
        icon StandardPixmapStr | StandardPixmap

        icon to use

        required
        size SizeType

        icon size

        15
        Source code in prettyqt/widgets/abstractbutton.py
        def set_style_icon(
            self,
            icon: widgets.style.StandardPixmapStr | widgets.QStyle.StandardPixmap,
            size: datatypes.SizeType = 15,
        ):
            """Set theme icon for the button.
        
            Args:
                icon: icon to use
                size: icon size
            """
            qicon = self.style().standardIcon(
                widgets.style.STANDARD_PIXMAP.get_enum_value(icon), None, self
            )
            self.set_icon(qicon)
            self.setIconSize(datatypes.to_size(size))
        

        :fa-brands-github: Show source on GitHub